package entities;

import menu.Settings;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;

import util.Vector2D;

public class AimingEnemy extends Enemy {

	private Entity target;
	private Vector2D targetPos;
	private Vector2D constAcceleration;

	public AimingEnemy(Entity target) throws SlickException {
		super("res/enemies/enemy03a.png");
		image = image.getScaledCopy(57, 25);
		maxHealth = (int) (5 * Settings.getfactor());
		score = 70;
		this.target = target;
//		setVelocity(new Vector2D(20, 20));
	}
	
	public void setTarget(Entity entity) {
		this.target = entity;
		reset();
	}

	@Override
	public void update(GameContainer gc, int delta) {
		super.update(gc, delta);
		if (level.isActive(target)) {
			if (targetPos == null) {
				targetPos = target.center();
				constAcceleration = (targetPos.subtract(pos)).getUnitVector().scale(
						400f);
			}
			acceleration = constAcceleration;
		}
	}

	@Override
	public String getName() {
		return "Aiming Enemy";
	}
	
	@Override
	public void reset() {
		super.reset();
		targetPos = null;
	}

}
